<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of loginMobile
 *
 * @author pudy
 */
class LoginMobile extends CI_Controller{
    //put your code here
    public function verify() {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        
        $this->load->model('userModel', 'userModel');
        
        $options = array('username' => $username, 'password' => $password);
        //$options = array('username' => 'guest');
        $getReturn = $this->userModel->getUsers($options);
        //$getReturn = $this->userModel->getUsers();
        
        //$id = $getReturn[0]->id;
        if (!$getReturn) {
            echo 0;
        } else {
            $id = $getReturn[0]->id;
            echo $id;
        }
        
        //print_r($getReturn);
        //echo 'un:'.$username.' pw:'.$password;
        /*if (is_bool($getReturn) && !$getReturn) {
            
            //echo 0;
            //Login gagal, gak ada user yang memenuhi
            //$message = 'Username and password do not match.';
            //$this->session->set_flashdata('message', $message);
            //redirect('/login', 'refresh');
        } else {
            //Authenticate success
            //Cek, kali aja ada yang 1 imel buat banyak akun:
            if (count($getReturn) == 1) {
                //Sign In OK
                //echo 1;
                /*$session_data = array(
                    'user_id' => $getReturn[0]->id,
                    'name' => $getReturn[0]->name,
                    'username' => $getReturn[0]->username
                );
                $this->session->set_userdata($session_data);*/
                /*echo $getReturn[0]->id;
                echo br(1);
                echo $getReturn[0]->name;
                echo br(1);
                echo $getReturn[0]->username;
                echo br(1);*/
                //redirect('/home', 'refresh');
            /*} else {
                //echo 0;
                //Sign In Not OK, ada 1 imel yang daftarin lebih dari 1 akun
                //show_error('More than 1 user with the same email.');
            }
        }*/
        
        //mysql_connect("localhost","root","");
        //mysql_select_db("finalprojectdb");
        //$query = "select * from user where username='".$username."' and password='".$password."'";
        //$result = mysql_query($query) or die("Unable to verify user because : ".mysql_error());
        //if (mysql_num_rows($result) == 0)
            //echo 0;
        //else
            //echo 1;
    }
}

?>
